//
//  UICircleTextField.m
//  erhuo
//
//  Created by Jingru Nie on 14/12/28.
//  Copyright (c) 2014年 集易（北京）科技有限公司. All rights reserved.
//

#import "UICircleTextField.h"

@interface UICircleTextField()
{
    UIEdgeInsets edgeInsets;
}
@end

#define MARGINTOP 6 //输入范围间隙

@implementation UICircleTextField

- (id)initWithFrame:(CGRect)frame
   withCornerRadius:(CGFloat)radius
{
    self = [super initWithFrame:frame];
    self.layer.cornerRadius = radius;
    self.clearButtonMode = UITextFieldViewModeWhileEditing;
    edgeInsets = UIEdgeInsetsMake(MARGINTOP, radius, MARGINTOP, radius);
    self.font = [UIFont fontWithName:self.font.fontName size:self.font.pointSize - (edgeInsets.top + edgeInsets.bottom) * 0.1];
    return self;
}

- (void)setTextEdgeInset:(UIEdgeInsets)insets {
    edgeInsets = insets;
    self.font = [UIFont fontWithName:self.font.fontName size:self.font.pointSize - (edgeInsets.top + edgeInsets.bottom) * 0.1];
}

- (CGRect)editingRectForBounds:(CGRect)bounds {
    CGRect rect = CGRectMake(bounds.origin.x + edgeInsets.left, bounds.origin.y + edgeInsets.top, bounds.size.width - edgeInsets.left - edgeInsets.right, bounds.size.height - edgeInsets.top - edgeInsets.bottom);
    return rect;
}

- (CGRect)textRectForBounds:(CGRect)bounds {
    CGRect rect = CGRectMake(bounds.origin.x + edgeInsets.left, bounds.origin.y + edgeInsets.top, bounds.size.width - edgeInsets.left - edgeInsets.right, bounds.size.height - edgeInsets.top - edgeInsets.bottom);
    return rect;
}

- (CGRect)placeholderRectForBounds:(CGRect)bounds {
    CGRect rect = CGRectMake(bounds.origin.x + edgeInsets.left, bounds.origin.y + edgeInsets.top, bounds.size.width - edgeInsets.left - edgeInsets.right, bounds.size.height - edgeInsets.top - edgeInsets.bottom);
    return rect;
}

/*- (void)drawPlaceholderInRect:(CGRect)bounds {
    if (bounds.size.width >= self.bounds.size.width) {
        [super drawPlaceholderInRect:CGRectMake(bounds.origin.x + edgeInsets.left, bounds.origin.y + edgeInsets.top, bounds.size.width - edgeInsets.left - edgeInsets.right, bounds.size.height - edgeInsets.top - edgeInsets.bottom)];
    }else {
        [super drawPlaceholderInRect:bounds];
    }
}*/

@end
